package com.util;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.internal.DefaultCommentGenerator;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GeneratorOverride extends DefaultCommentGenerator {
	@Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        // 添加字段注释

      field.addJavaDocLine("/**");

    // field.addJavaDocLine(" * <pre>");
     if (introspectedColumn.getRemarks() != null){
    	 field.addJavaDocLine(" * " + introspectedColumn.getRemarks());
     }
     else{
    	 field.addJavaDocLine(" *" );
     }
   //  sb.append(" * 表字段 : ");
    // sb.append(introspectedTable.getFullyQualifiedTable());
   //  sb.append('.');
    // sb.append(introspectedColumn.getActualColumnName());
    // field.addJavaDocLine(sb.toString());
    // field.addJavaDocLine(" * </pre>");
 //    field.addJavaDocLine(" * ");
     //addJavadocTag(field, false);
     field.addJavaDocLine(" */");

//      第二种注释
        /*StringBuffer sb = new StringBuffer();

        if (introspectedColumn.getRemarks() != null)
            sb.append(" //" + introspectedColumn.getRemarks());
        sb.append("  --- ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        sb.append('.');
        sb.append(introspectedColumn.getActualColumnName());
        field.addJavaDocLine(sb.toString());*/
	}

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete){
        StringBuilder sb = new StringBuilder();
        innerClass.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        innerClass.addJavaDocLine(sb.toString());
        sb.setLength(0);
        sb.append(" * system ");
        sb.append(" ");
        sb.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        innerClass.addJavaDocLine(" */");
    }
}
